<%@ include file="../include/taglib.jsp" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div class="modal-body">
    <div class="row">
        <button type="button" class="btn btn-theme04"
                onclick="del(${sysMenu.id});">删除菜单
        </button>
        <button type="button" class="btn btn-theme" id="searchSubmit"
                onclick="edit(${sysMenu.id});">修改菜单
        </button>
        <button type="button" class="btn btn-theme02"
                onclick="$('#editForm input').val('');$('#pid').val(${sysMenu.id});$('#pid_tip').css('color','green');$('#pid_tip').html(' * 新增 *');">
            添加菜单
        </button>
    </div>
    <br>
    <div class="row">
        <form id="editForm" class="form-horizontal style-form">
            <input type="hidden" value="${sysMenu.id}" name="id" id="id"/>
            <div class="form-group">
                <label class="col-sm-2 control-label">父节点PID</label>
                <div class="col-sm-6">
                    <input placeholder="" type="text" name="pid" id="pid"
                           value="${sysMenu.pid}"
                           readonly maxlength="11"/>
                    <label><p id="pid_tip" style="color: red;"> * 修改 * </p></label>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">菜单名称</label>
                <div class="col-sm-6">
                    <input type="text" size="20" name="menuName" value="${sysMenu.menuName}" maxlength="32"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">链接地址</label>
                <div class="col-sm-6">
                    <input type="text" name="path" value="${sysMenu.path}"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">域名</label>
                <div class="col-sm-6">
                    <input type="text" name="domain" value="${sysMenu.domain}"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">图标</label>
                <div class="col-sm-6">
                    <input type="text" name="icon" value="${sysMenu.icon}"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">同级排序</label>
                <div class="col-sm-6">
                    <input type="text" name="sort" value="${sysMenu.sort}" maxlength="11"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">备注</label>
                <div class="col-sm-8">
                <textarea class="form-control"
                          value="${sysMenu.note}"
                          name="note">${sysMenu.note}</textarea>
                </div>
            </div>
        </form>
    </div>
</div>
<div class="modal-footer">
    <button data-dismiss="modal" class="btn btn-default" type="button" id="cancelBtn">取消</button>
    <button class="btn btn-theme" type="button" id="saveBtn">保存</button>
</div>
<!-- modal -->
<script type="text/javascript">
    $(function () {
        $("#saveBtn").bind("click", function () {
            var data = $("#editForm").serializeArray();
            var package = new AJAXPacket("${ctx}/sysmenu/save");
            package.data.data = data;
            core.ajax.sendPacket(package, function (response) {
                if (response.data.success) {
                    alertMsg.correct("成功！");
                    var keyWord = $("input[name=menuName]").val();
                    jumpMenu('${ctx}/sysmenu/page?keyWord=' + keyWord);
                } else {
                    alertMsg.error(response.data.errMsg);
                }
            });
            package = null;
        });
        $("#cancelBtn").bind("click", function () {
            $('#selectable-output').empty();
        });
    });

    function edit(id) {
        var package = new AJAXPacket("${ctx}/sysmenu/edit");
        package.data.add("id", id);
        core.ajax.sendPacketHtml(package, function (data) {
            $("#selectable-output").html(data);
        });
        package = null;
    }

    function del(id) {
        var del = function () {
            var package = new AJAXPacket("${ctx}/sysmenu/delete");
            package.data.add("id", id);
            core.ajax.sendPacket(package, function (response) {
                if (response.data.success) {
                    alertMsg.correct("成功！");
                    jumpMenu('${ctx}/sysmenu/page');
                } else {
                    alertMsg.error(response.data.errMsg);
                }
            });
            package = null;
        }
        alertMsg.confirm('确定执行此删除操作吗？', del);
    }
</script>